<?php

namespace workin\modules\increment\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use workin\modules\increment\models\IdcardCheck;

/**
 * IdcardCheckSearch represents the model behind the search form of `workin\modules\increment\models\IdcardCheck`.
 */
class IdcardCheckSearch extends IdcardCheck
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'result_auth_status', 'result_is_real', 'result_exp_status'], 'integer'],
            [['grant_key', 'api_key', 'business_code', 'name', 'id_card', 'order_report_id', 'search_index', 'result_detail', 'result_photo_base64', 'result_result', 'result_report_id', 'result_busi_code', 'result_busi_msg', 'result_extend_data'], 'safe'],
            [['result_service_fee'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = IdcardCheck::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'result_auth_status' => $this->result_auth_status,
            'result_service_fee' => $this->result_service_fee,
            'result_is_real' => $this->result_is_real,
            'result_exp_status' => $this->result_exp_status,
        ]);

        $query->andFilterWhere(['like', 'grant_key', $this->grant_key])
            ->andFilterWhere(['like', 'api_key', $this->api_key])
            ->andFilterWhere(['like', 'business_code', $this->business_code])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'id_card', $this->id_card])
            ->andFilterWhere(['like', 'order_report_id', $this->order_report_id])
            ->andFilterWhere(['like', 'search_index', $this->search_index])
            ->andFilterWhere(['like', 'result_detail', $this->result_detail])
            ->andFilterWhere(['like', 'result_photo_base64', $this->result_photo_base64])
            ->andFilterWhere(['like', 'result_result', $this->result_result])
            ->andFilterWhere(['like', 'result_report_id', $this->result_report_id])
            ->andFilterWhere(['like', 'result_busi_code', $this->result_busi_code])
            ->andFilterWhere(['like', 'result_busi_msg', $this->result_busi_msg])
            ->andFilterWhere(['like', 'result_extend_data', $this->result_extend_data]);

        return $dataProvider;
    }
}
